#include <fstream>
#include <vector>
#include <utility>
#include <algorithm>
using namespace std;


int main() {
    ifstream in("in.txt");
    ofstream out("out.txt");

    int n;
    in >> n;
    int a,b;
    in >> a>>b;

    vector<pair<double, pair<int,int> > > edges;

    while (!in.eof()) {
        int a,b;
        in >> a >> b;
        double w;
        in >> w;
        edges.push_back(make_pair(w,make_pair(a,b)));
    }

    vector< pair<int,int> > mst;
    mst.push_back(make_pair(a,b));

    vector<int> tree_id(n);
    for (int i=0; i<n; i++)
        tree_id[i] = i;
    tree_id[b] = a;

    sort(edges.begin(), edges.end());

    for (int i=0; i<edges.size(); i++) {
        int a = edges[i].second.first, b = edges[i].second.second, w = edges[i].first;
        if (tree_id[a] != tree_id[b]) {
            mst.push_back(make_pair(a,b));
            int old_id = tree_id[b], new_id = tree_id[a];
            for (int j=0; j<n; j++)
                if (tree_id[j] == old_id)
                    tree_id[j] = new_id;
        }

    }

    if (mst.size() == n-1) {
        out << "YES\n";
        for (int i=0; i<mst.size(); i++)
            out << mst[i].first << ' ' << mst[i].second << '\n';

    } else
        out << "NO\n";

    return 0;

}
